home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_10_03 / 1003020b < prev    next >
Text File  |  1991-12-17  |  500b  |  37 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #define STACK_SIZE 30
  5.  
  6. static int stack[STACK_SIZE];
  7.  
  8. static size_t stack_ptr = 0;
  9.  
  10. void push(int value)
  11. {
  12.  
  13. #ifdef TRACE
  14. printf("pushing: %c\n", value);
  15. #endif
  16.  
  17.     if (stack_ptr == STACK_SIZE)
  18.         printf("Stack is full\n");
  19.     else
  20.         stack[stack_ptr++] = value;
  21. }
  22.  
  23. int pop(void)
  24. {
  25.     if (stack_ptr == 0) {
  26.         printf("Stack is empty\n");
  27.         return 0;
  28.     }
  29.  
  30. #ifdef TRACE
  31. printf("popping: %c\n", stack[stack_ptr - 1]);
  32. #endif
  33.  
  34.     return stack[--stack_ptr];
  35. }
  36.  
  37.